﻿using System.Data;

namespace StampController.BL
{
    public class DocumentImpl
    {
        public bool DeleteDocument(string requestId, string link)
        {
            try
            {
                using (var dbHelper = new DbHelper())
                {
                    object[,] parameter =
                    {
                        {"@RequestID", requestId},
                        {"@Link", link.StartsWith("/Upload") ? link.Remove(0, "/Upload".Length) : link}
                    };
                    int i = dbHelper.ExecuteNonQuery("DELETE FROM Document WHERE Link = @Link AND RequestID = (SELECT TOP 1 ID FROM RequestForm WHERE RequestID = @RequestID)", CommandType.Text, parameter);

                    return i > 0;
                }
            }
            catch
            {
                throw;
            }
        }
    }
}
